﻿<navigation:Page xmlns:my="clr-namespace:SMS.Views.SalesModule"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                 xmlns:SMS_ViewModel_SalesModule="clr-namespace:SMS.ViewModel.SalesModule"
                 x:Class="SMS.Views.SalesModule.SalePage"
                 mc:Ignorable="d"
                 Title="Sale"
                 d:DesignHeight="300"
                 d:DesignWidth="1000"
                 xmlns:my1="clr-namespace:SMS.Controls;assembly=SMS.Controls">
    <UserControl.Resources>

    </UserControl.Resources>
    <Border BorderBrush="Black"
            HorizontalAlignment="Left"
            BorderThickness="1">
        <Grid x:Name="LayoutRoot"
              Margin="5"
              HorizontalAlignment="Left">
            <Grid.RowDefinitions>
                <RowDefinition Height="30" />
                <RowDefinition Height="2" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="30" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="150" />
                    <ColumnDefinition Width="0" />
                    <ColumnDefinition Width="200" />
                    <ColumnDefinition Width="200" />
                    <ColumnDefinition Width="100" />
                    <ColumnDefinition Width="100" />
                    <ColumnDefinition Width="100" />
                    <ColumnDefinition Width="100" />
                    <ColumnDefinition Width="100" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="50" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="No." />
                    <TextBlock Text="Product ID"
                               Grid.Column="1"
                               HorizontalAlignment="Left" />
                </Grid>
                <TextBlock Text="Product Name"
                           Margin="5,0"
                           Grid.Column="2"
                           HorizontalAlignment="Left" />
                <TextBlock Text="Brand Name"
                           Margin="5,0"
                           Grid.Column="3"
                           HorizontalAlignment="Left" />
                <TextBlock Text="Unit Price"
                           Grid.Column="4"
                           HorizontalAlignment="Right" />
                <TextBlock Text="Quantity"
                           TextAlignment="Right"
                           Margin="5,0,0,0"
                           Grid.Column="5" />
                <TextBlock Text="Total Amount"
                           Grid.Column="6"
                           Margin="5,0,0,0"
                           TextAlignment="Right" />
                <TextBlock Text="Discount"
                           HorizontalAlignment="Right"
                           Margin="5,0,0,0"
                           Grid.Column="7" />
                <TextBlock Text="Billed Amount"
                           HorizontalAlignment="Right"
                           Margin="5,0,0,0"
                           Grid.Column="8" />
            </Grid>
            <Rectangle Grid.Row="1"
                       Style="{StaticResource SeperatorRectangle}" />
            <ListBox Grid.Row="2"
                     HorizontalAlignment="Stretch"
                     VerticalAlignment="Top"
                     BorderBrush="{x:Null}"
                     ItemsSource="{Binding Path=SaleDetailList, Mode=TwoWay}">
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="HorizontalAlignment"
                                Value="Stretch" />

                    </Style>

                </ListBox.ItemContainerStyle>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition Height="2" />
                            </Grid.RowDefinitions>
                            <my:SaleDetailForm />
                            <Rectangle Grid.Row="1"
                                       Style="{StaticResource SeperatorRectangle}" />
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            <Grid  Grid.Row="3">
                <Grid.RowDefinitions>
                    <RowDefinition Height="2" />
                    <RowDefinition Height="30" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Rectangle Fill="Gray"
                           Height=".5"
                           VerticalAlignment="Center"
                           Margin="0" />
                <Grid DataContext="{Binding SaleHistoryData}"
                      Grid.Row="1"
                      Grid.RowSpan="2">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150" />
                        <ColumnDefinition Width="0" />
                        <ColumnDefinition Width="200" />
                        <ColumnDefinition Width="200" />
                        <ColumnDefinition Width="100" />
                        <ColumnDefinition Width="100" />
                        <ColumnDefinition Width="100" />
                        <ColumnDefinition Width="100" />
                        <ColumnDefinition Width="100" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="50" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="{Binding Path=SalesDetailList.Count}" />

                    </Grid>

                    <TextBlock Text="{Binding Path=TotalSellingPrice, StringFormat=N2}"
                               Grid.Column="6"
                               Margin="5,0,0,0"
                               HorizontalAlignment="Right" />
                    <TextBlock Text="{Binding Path=Discount, StringFormat=N2}"
                               TextAlignment="Right"
                               Margin="10,0,0,0"
                               Grid.Column="7" />
                    <TextBlock Text="{Binding Path=ActualSelliingPrice, StringFormat=N2}"
                               HorizontalAlignment="Right"
                               Margin="5,0,0,0"
                               Grid.Column="8" />
                </Grid>
                <Grid Grid.Row="2">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150" />
                        <ColumnDefinition Width="0" />
                        <ColumnDefinition Width="200" />
                        <ColumnDefinition Width="200" />
                        <ColumnDefinition Width="100" />
                        <ColumnDefinition Width="100" />
                        <ColumnDefinition Width="100" />
                        <ColumnDefinition Width="100" />
                        <ColumnDefinition Width="100" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <StackPanel Grid.Column="7">
                        <TextBlock Text="Received:"
                                   TextAlignment="Right"
                                   Margin="5,5" />
                        <TextBlock Text="Return:"
                                   HorizontalAlignment="Right"
                                   Margin="5,0" />
                    </StackPanel>
                    <StackPanel Grid.Column="8"
                                DataContext="{Binding SaleHistoryData}">
                        <TextBox Text="{Binding Path=Received, Mode=TwoWay, StringFormat=N2}"
                                 Grid.Column="7"
                                 TextAlignment="Right" />
                        <TextBlock Text="{Binding Path=Return, StringFormat=N2}"
                                   TextAlignment="Right"
                                   Margin="0,5,0,0" />
                    </StackPanel>
                    <Border Grid.ColumnSpan="7"
                            BorderBrush="Black"
                            BorderThickness=".5"
                            Margin="2">
                        <Grid Margin="2">
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                                <ColumnDefinition />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <StackPanel Orientation="Horizontal"
                                        VerticalAlignment="Bottom">
                                <TextBlock Text="Customer:"
                                           Width="100" />
                                <my1:SMSCustomer VerticalAlignment="Bottom"
                                                 Width="150"
                                                 SelectedCustomer="{Binding Path=SelectedCustomer, Mode=TwoWay}"
                                                 Margin="5,0" />
                            </StackPanel>
                            <StackPanel Grid.Row="1"
                                        Orientation="Horizontal">
                                <TextBlock Text="Balance:    "
                                           Width="100" />

                                <TextBox Text="{Binding Path=CustomerBalance, StringFormat=N}"
                                         Margin="5,0"
                                         IsReadOnly="True"
                                         Width="150" />
                            </StackPanel>
                            <StackPanel Grid.Column="1"
                                        Grid.Row="1">
                                <HyperlinkButton Content="Show Detail"
                                                 Command="{Binding Path=ShowTransactionCommand}" />
                            </StackPanel>
                            <TextBlock Text="Paid Amount: "
                                       Grid.Column="3"
                                       HorizontalAlignment="Right"
                                       Grid.Row="3" />
                            <StackPanel Grid.Column="4"
                                        DataContext="{Binding Path=SaleHistoryData}"
                                        Grid.RowSpan="2">
                                <CheckBox Content="Is Paid"
                                          x:Name="chkIsPaid"
                                          IsChecked="{Binding Path=Is_Paid, Mode=TwoWay}" />
                                <TextBox Text="{Binding Path=PaidAmount, Mode=TwoWay, StringFormat=N2}"
                                         TextAlignment="Right"
                                         IsEnabled="{Binding Path=IsChecked, ElementName=chkIsPaid}" />
                            </StackPanel>
                        </Grid>
                    </Border>
                </Grid>
            </Grid>
            <Grid Grid.Row="4">
                <Button Content="+"
                        HorizontalAlignment="Right"
                        Command="{Binding Path=AddCommand}"
                        Width="25" />
                <Button Content="&lt;-"
                        HorizontalAlignment="Right"
                        Command="{Binding Path=UndoCommand}"
                        Margin="0,0,30,0" />
                <Button Content="Save"
                        HorizontalAlignment="Right"
                        Command="{Binding Path=SaveCommand}"
                        Margin="0,0,60,0" />
                <Button Content="New"
                        HorizontalAlignment="Right"
                        Command="{Binding Path=NewCommand}"
                        Margin="0,0,105,0" />
            </Grid>
            <Grid HorizontalAlignment="Right"
                  Margin="4"
                  Visibility="{Binding Path=ReceiptVisiblity, FallbackValue=Visible}"
                  x:Name="receiptGrid"
                  Background="White"
                  VerticalAlignment="Top"
                  Grid.RowSpan="5">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <my:SaleReceipt  VerticalAlignment="Stretch"
                                 Margin="0,-30,0,0"
                                 DataContext="{Binding Path=SaleHistoryData}"
                                 Grid.Row="1" />
                <Button Content="X"
                        HorizontalAlignment="Right"
                        Margin="0,5,5,-5"
                        ToolTipService.ToolTip="Click to remove this item"
                        Command="{Binding Path=CloseReceipt}"></Button>

            </Grid>
            <Grid Grid.Row="4">
                <my1:ErrorControl HorizontalAlignment="Left"
                                  Name="errorControl1"
                                  VerticalAlignment="Top" />
            </Grid>
        </Grid>
    </Border>
</navigation:Page>
